define(['jquery', 'bootstrap', 'select2', 'validate', 'validate.en', 'koala-search', 'shiftform', 'modalSearch'],
function($, validate) {
  return {
    
    init: function() {
      this.initPage();
      this.initQuery();
    },
    
    initPage: function(){
    	$(document).find('form').bind('reset', function(e){
            $(this).find(".select2").select2("val", "");
      	})
        
        $('select[name="organizationIds"]').select2({
          theme: "classic",
          placeholder : '请选择',
          minimumResultsForSearch : -1,
          allowClear : true,
        });
        
        $(document).find('form').bt_validate();
    },
    
    initQuery: function() {
      
      $('[data-target="#modal-search-fromloadplace"]').modalsearch({
        url: window.__CTX__.root + '/load-places/query',
        tableColumns: ['出发地代码', '出发地名称'],
        tableValues: ['code', 'name'],
        displayValues: ['code', 'name'],
        values: ['id']
      });
      
      $('[data-target="#modal-search-toloadplace"]').modalsearch({
        url: window.__CTX__.root + '/load-places/query',
        tableColumns: ['到达地代码', '到达地名称', 'id'],
        tableValues: ['code', 'name', 'id'],
        displayValues: ['code', 'name'],
        values: ['id']
      });
      
      var options = {
        time: 1000,
        url: window.__CTX__.root + "/load-places/query",
        queryName: "code",
        value: ["id"],
        display: ["code", "name"]
      }
      
      $('.fromloadplace-search').koalaSearch(options);
      $('.toloadplace-search').koalaSearch(options);
      
      $(document).on("koala.search.value.changed", ".fromloadplace-search, .toloadplace-search", function(){
        console.log($(this).next().val());
        // TODO 其他查询后的逻辑
      })
    }
  }
})